package com.webapp.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.webapp.domain.entity.Disputes;
import com.webapp.domain.entity.DisputesData;

/**
 * 纠纷咨询内容DAO
 * @author zern
 *
 */
@Repository("disputesDataDAO")
public class DisputesDataDAO extends AbstractDAO<DisputesData>{

	/**
	 * 通过纠纷id查询纠纷资料
	 * @param disputesId
	 * @return
	 */
	public DisputesData getDisDataByDisputes(String disputesId){
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(DisputesData.class);
		detachedCriteria.add(Restrictions.eq("disputes.id", disputesId));
		return getByCriteria(detachedCriteria);
	}
	
	/**
	 * 通过纠纷id查询纠纷资料
	 * @param disputesId
	 * @return
	 */
	public List<DisputesData> findDisputesDataByDisputes(Disputes disputes){
		return this.find("where disputes_data。disputes = ?", disputes);
	}
	
	/**
	 * 更新资料描述及内容
	 * @param data
	 */
	public int updateData(DisputesData data){
		String hql = "update DisputesData data set data.title = :title, data.content = :content where data.id = :id";
		Query query = getSession().createQuery(hql).setString("title", data.getTitle())
				.setString("content", data.getContent())
				.setLong("id", data.getId());
		return query.executeUpdate();
	}
	
	
}
